#pragma once
#include "stdafx.h"
#include "common.h"
#include "structs.h"
#include "typedef.h"

class Cmkyaffs2Dlg;

class Cmkyaff2Image
{
public:
	CFile file;
	int n_obj;
	int obj_id;
	int nObjects, nDirectories, nPages;
	int outFile;
	int error;
	int convert_endian;
	CListBox *m_list ;
	objItem *obj_list;
	__u8 *oob_buf;
	Cmkyaffs2Dlg *m_pDlg;
public:
	Cmkyaff2Image();
	Cmkyaff2Image(BOOL bigendian);
	~Cmkyaff2Image(void);
	int mkyaffs2Imagefile(CString srcpath, CString destname,Cmkyaffs2Dlg *pDlg);
	int write_object_header(int objId, yaffs_ObjectType t, struct stat * s, int parent, const char * name, int equivalentObj , const char * alias);
	int process_directory(int parent,const CString path);
	void add_obj_to_list(dev_t dev, ino_t ino, int obj);
	int find_obj_in_list(dev_t dev, ino_t ino);
	void little_to_big_endian(yaffs_Tags* tagsPtr);
	void nand_trans_result(__u8 reg2, __u8 reg3, __u8 * ecc_code);
	int nand_calculate_ecc(const __u8* dat, __u8* ecc_code);
	void nand_prepare_oobbuf(__u8* oob_buf, __u8* fs_buf, struct nand_oobinfo * oobsel);
	int write_chunk(__u8* data, __u32 objId , __u32 chunkId , __u32 nBytes);
	void object_header_little_to_big_endian(yaffs_ObjectHeader* oh);
};
